  <template>
  <div class="customer">
    <div class="customer_top">
      <!-- <el-button type="primary" size="medium" @click="saveProduct"
        >添加</el-button -->
      <!-- > -->
      <el-input v-model="input" placeholder="请输入姓名"></el-input>
      <!-- <el-button type="primary" size="medium" @click="searchButton"
        >查询</el-button -->
      <!-- > -->
    </div>
    <div class="customer_center">
      <el-table :data="customer" stripe style="width: 100%">
        <el-table-column prop="id" label="编号" width="140"> </el-table-column>
        <el-table-column prop="realname" label="姓名" width="200">
        </el-table-column>
        <el-table-column prop="telephone" label="手机号" width="140">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="440">
        </el-table-column>
        <el-table-column label="操作">
          <!-- <template slot-scope="scope">
            <a href="#" @click="deleteById(scope.row)">删除</a>
            <a href="#" @click="updateProduct(scope.row)">编辑</a>
            <a href="#" @click="details(scope.row.id)">详情</a>
          </template> -->
        </el-table-column>
      </el-table>
    </div>
    <div class="customer_footer">
      <!-- -----------分页------------- -->
      <!-- <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination> -->
    </div>
    <!-- ----------------添加 编辑功能-------------------------------------- -->
    <!-- <el-dialog :title="title" :visible.sync="dialogFormVisible">
      <el-form :model="form" :rules="rules" ref="myform">
        <el-form-item
          label="产品名称"
          :label-width="formLabelWidth"
          prop="name"
        >
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="产品价格"
          :label-width="formLabelWidth"
          prop="price"
        >
          input表单默认内容为字符串,通过修饰符转换成数字
         <el-input v-model.number="form.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="所属栏目"
          :label-width="formLabelWidth"
          prop="categoryId"
        >
          <el-select v-model="form.categoryId" placeholder="请选择活动区域">
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="item in category"
              :key="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品介绍" :label-width="formLabelWidth">
          <el-input type="textarea" v-model="form.description"></el-input>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth">
          <el-button type="primary">点击上传</el-button>
          <div><span class="note">只能上传png格式，大小不超过500kb</span></div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('myform')"
          >确 定</el-button
        > 
      </div> 
    </el-dialog> -->
  </div>
</template>

  <script>
import Qs from "querystring";
export default {
  data() {
    return {
      //表单内容
      input: "",
      // 产品数据
      customer: [],
      //栏目数据
      category: [],
      // 当前点击分页
      currentPage: 1,
      //实际请求分页
      requirePage: 0,
      // 产品渲染个数
      pageSize: 10,
      //产品总数
      total: 0,
      title: "添加产品信息",
      //模态框
      dialogFormVisible: false,
      form: {
        name: "",
        price: "",
        categoryId: "",
        description: "",
      },
      formLabelWidth: "100px",
      //表单验证规则
      rules: {
        name: [
          {
            required: true,
            message: "请输入产品名称",
            trigger: "blur",
          },
          {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
        price: [
          {
            required: true,
            message: "价格不能为空",
          },
          {
            type: "number",
            message: "价格必须为数字值",
          },
        ],
        categoryId: [
          {
            required: true,
            message: "请选择所属栏目",
            trigger: "change",
          },
        ],
      },
    };
  },
  methods: {
    //分页发送请求
    // 形参name用来接收 产品名称 查询
    customer_axios(name) {
      if (name) {
        //查询
        var data = {
          page: this.requirePage,
          pageSize: this.pageSize,
          name: name,
        };
      } else {
        var data = {
          page: this.requirePage,
          pageSize: this.pageSize,
        };
      }
      this.$axios.post("/customer/query", Qs.stringify(data)).then((respond) => {
        console.log(respond);
        this.customer = respond.data.data.list;
        this.total = respond.data.data.total;
      });
    },
    //查询所有栏目函数
    // findAllCategory() {
    //   return this.$axios.get("/category/findAll");
    // },
    // handleCurrentChange(val) {
    //   this.requirePage = val - 1;
    //   this.customer_axios();
    // },
    // 添加按钮功能
    // saveProduct() {
    //   this.form = {
    //     name: "",
    //     price: "",
    //     categoryId: "",
    //     description: "",
    //   };
    //   this.dialogFormVisible = true;
    //   this.title = "添加产品信息";
    // },
    //编辑按钮功能
    // updateProduct(row) {
    //   this.dialogFormVisible = true;
    //   this.title = "编辑产品信息";
    //   this.form = {
    //     id: row.id,
    //     name: row.name,
    //     price: row.price,
    //     categoryId: row.categoryId,
    //     description: row.description,
    //   };
    // },
    //添加确定按钮
    // submitForm(formName) {
    //   let that = this;
    //   //1.获取表单数据,表单验证
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       //2.发送请求
    //       that.$axios
    //         .post("/product/saveOrUpdate", Qs.stringify(that.form))
    //         .then((response) => {
    //           if (response.data.status === 200) {
    //             this.$message({
    //               message: "保存成功",
    //               type: "success",
    //             });
    //             that.product_axios();
    //           } else {
    //             this.$message.error("保存失败");
    //           }
    //           that.dialogFormVisible = false;
    //         });
    //     } else {
    //       return false;
    //     }
    //   });
    // },
    //查询按钮功能,根据input输入的产品名
    // searchButton() {
    //   if (this.input) {
    //     this.product_axios(this.input);
    //   } else {
    //     this.product_axios();
    //   }
    // },
    //删除按钮
    // deleteById(row) {
    //   let that = this;
    //   let id = row.id;
    //   that.$axios
    //     .get("/product/deleteById", {
    //       params: {
    //         id: id,
    //       },
    //     })
    //     .then((respond) => {
    //       if (respond.data.status === 200) {
    //         this.$message({
    //           type: "success",
    //           message: "删除成功!",
    //         });
    //         this.currentPage= 1;
    //         this.currentPage1 = 0;
    //         that.product_axios();
    //       } else {
    //         this.$message.error("删除失败");
    //       }
    //     });
    // },
    //详情按钮
    // details(id) {
    //   //编程式路由传值
    //   this.$router.push({
    //     path: "/productDetails/index",
    //     query: {
    //       id: id,
    //     },
    //   });
    // },
  },
  // computed: {
  //   customerList() {
  //     var that = this;
  //     //1.获取所有产品信息
  //     // console.log(this.product);
  //     //2.获取所有栏目信息
  //     // console.log(this.category);
  //     //3.用产品的id匹配栏目id,将栏目对象的name赋值给产品对象
  //     //遍历产品
  //     this.product.forEach((item) => {
  //       //遍历栏目匹配 所属产品
  //       for (var i = 0; i < that.category.length; i++) {
  //         if (item.categoryId === that.category[i].id) {
  //           //将匹配到的栏目name插入到产品中，渲染到页面
  //           item.categoryName = that.category[i].name;
  //         }
  //       }
  //     });
  //     return this.product;
  //   },
  // },
  created() {
      this.customer_axios();

    //查询所有栏目
    // this.findAllCategory().then((response) => {
    //   this.category = response.data.data;
    //   //查询所有产品
    // });
  },
};
</script>

  <style lang="scss" scoped>
.customer {
  padding: 20px;

  .customer_top .el-input {
    width: 20%;
    margin: 0 10px;
  }

  .customer_center a {
    padding-right: 10px;
  }

  .customer_center a:hover {
    color: #409eff;
  }

  .el-dialog .note {
    color: #999999;
    font-size: 12px;
  }
}
</style>
